package sort;

/**
 * @Author leecho
 * @Date: 2021/10/17 11:56
 * @Version 1.0
 */

public class SelectSort {
    public static void main(String[] args) {
        int[] ints = {1, 3, 6,2, 5, 4};
        SelectSort selectSort = new SelectSort();
        selectSort.selectSort(ints);
        for (int i : ints) {
            System.out.print(i + " ");
        }

    }

    /*
    * 思路
    * - 将每一个数字与后面的进行比较
    *   - 小于交换
    * */
    public void selectSort(int[] arr){
        int temp = 0;
        for (int i = 0; i < arr.length; i++) {
            for (int j = i+1; j < arr.length; j++) {
                temp = arr[i];
                if (arr[j] < temp){
                    temp = arr[j];
                    arr[j] = arr[i];
                    arr[i] = temp;
                }
            }
        }
    }
}
